/**
 * 
 */
package com.honeywell.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hiynn 
 * @CreateDate 2016年6月23日下午2:25:05
 * 解决跨域所需要的filter
 */
public class SimpleCORSFilter implements Filter {
	

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		
		HttpServletResponse resp = (HttpServletResponse)response;   
		resp.setHeader("Access-Control-Allow-Origin", "*");		
		resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");				
		resp.setHeader("Access-Control-Allow-Headers", "Origin, x-requested-with,  Access-Control-Allow-Headers,"
				+ " Content-Type, Accept, Authorization");
        chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		
	}

	@Override
	public void destroy() {
		
	}


}
